package com.single.dao;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper;
import org.springframework.stereotype.Repository;

import com.base.dao.TemplateDaoImpl;
import com.data.entity.ChargeDay;
import com.data.entity.ChargeMonth;
import com.data.entity.ChargeWeek;
@Repository("singleDao")
public class SingleDaoImpl extends TemplateDaoImpl<ChargeDay, Integer>implements SingleDao{
	/**
	 * 单机电度电费日统计
	 * @param equId
	 * @param model
	 */
	@Override
	public List<ChargeDay> getChargeDayByDate(int id, String startDate,String endDate, String isLine) {
		StringBuilder sb=new StringBuilder("select belongDate,COALESCE(SUM(relativeComp),0)relativeComp, COALESCE(SUM(charge),0) charge from chargeDay where ");
		if(isLine.equals("Y")){
			sb.append(" lineId=:id ");
		}else{
			sb.append(" equId=:id ");
		}
		sb.append("  and DATE_FORMAT(belongDate,'%Y-%m-%d')>=:startDate and DATE_FORMAT(belongDate,'%Y-%m-%d')<=:endDate group by belongDate ");
		Map<String, Object> params=new HashMap<String, Object>();
		params.put("id", id);
		params.put("startDate", startDate);
		params.put("endDate", endDate);
		return jt.query(sb.toString(), params, ParameterizedBeanPropertyRowMapper.newInstance(ChargeDay.class));
	}
	/**
	 * 单机电度电费周统计
	 * @param id
	 * @param belongYear
	 * @param startWeek
	 * @param endweek
	 * @param isLine
	 * @return
	 */
	@Override
	public List<ChargeWeek> getChargeWeekByWeek(int id, int belongYear,int startWeek, int endweek, String isLine) {
		StringBuilder sb=new StringBuilder("select belongYear,belongWeek,COALESCE(SUM(relativeComp),0)relativeComp, COALESCE(SUM(charge),0) charge from chargeWeek where ");
		if(isLine.equals("Y")){
			sb.append(" lineId=:id ");
		}else{
			sb.append(" equId=:id ");
		}
		sb.append("  and belongYear=:belongYear and belongWeek>=:startWeek and belongWeek<=:endweek group by belongWeek ");
		Map<String, Object> params=new HashMap<String, Object>();
		params.put("id", id);
		params.put("belongYear", belongYear);
		params.put("startWeek", startWeek);
		params.put("endweek", endweek);
		return jt.query(sb.toString(), params, ParameterizedBeanPropertyRowMapper.newInstance(ChargeWeek.class));
	}
	/**
	 * 单机电度电费月统计
	 * @param id
	 * @param startMonth
	 * @param endMonth
	 * @param isLine
	 * @return
	 */
	@Override
	public List<ChargeMonth> getChargeMonthByMonth(int id,String startMonth,String endMonth,String isLine) {
		StringBuilder sb=new StringBuilder("select belongDate,COALESCE(SUM(relativeComp),0)relativeComp, COALESCE(SUM(charge),0) charge from chargeMonth where ");
		if(isLine.equals("Y")){
			sb.append(" lineId=:id ");
		}else{
			sb.append(" equId=:id ");
		}
		sb.append("  and belongDate>=:startMonth and belongDate<=:endMonth group by belongDate ");
		Map<String, Object> params=new HashMap<String, Object>();
		params.put("id", id);
		params.put("startMonth", startMonth);
		params.put("endMonth", endMonth);
		return jt.query(sb.toString(), params, ParameterizedBeanPropertyRowMapper.newInstance(ChargeMonth.class));
	}
}
